home *** CD-ROM | disk | FTP | other *** search
/ Java Certification Exam Guide / McGrawwHill-JavaCertificationExamGuide.iso / pc / Web Links and Code / ans / chap12 / exer1204 / Ex1204c.java < prev    next >
Encoding:
Java Source  |  1997-04-20  |  481 b   |  27 lines

  1. class Ex1204c {
  2.    public static void main(String[] args) {
  3.       MyThread t1 = new MyThread(1);
  4.       MyThread t2 = new MyThread(2);
  5.  
  6.       t1.other = t2;
  7.       t2.other = t1;
  8.  
  9.       t1.start();
  10.       t2.start();
  11.    }
  12. }
  13.  
  14. class MyThread extends Thread {
  15.    int id;
  16.    MyThread other;
  17.    MyThread(int id) {
  18.       this.id = id;
  19.    }
  20.  
  21.    public void run() {
  22.       for (int i = 0; i < 100; i++) {
  23.          System.out.println("My id is " + id);
  24.       }
  25.    }
  26. }
  27.